package com.jiaxue.admin.handler;

import java.io.IOException;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

import com.jiaxue.admin.model.ReturnObj;

@ControllerAdvice
public class ControllerAdviceExceptionHandler {
private static final Logger LOG = LoggerFactory.getLogger(ControllerAdviceExceptionHandler.class);
	
	/**
	 * 处理框架返回异常
	 * @param e
	 * @param request
	 * @param response
	 * @return
	 * @throws IOException
	 */
    @ExceptionHandler
    public @ResponseBody ReturnObj handleException(Exception e,HttpServletRequest request,HttpServletResponse response) throws IOException{
    	LOG.error(e.getMessage());
    	return  new ReturnObj(-1,e.getMessage(),null);
    }
    
}
